package cn.zxf.spring.small.function.task_executor.demo;

import java.util.concurrent.Executor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@ComponentScan( "cn.zxf.spring.small.function.task_executor.demo" )
@EnableAsync // 1
public class TaskExecutorConfig implements AsyncConfigurer {// 2

    @Override
    public Executor getAsyncExecutor() {// 2
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize( 5 );
        taskExecutor.setMaxPoolSize( 10 );
        taskExecutor.setQueueCapacity( 25 );
        taskExecutor.initialize();
        return taskExecutor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }

}
